<?
include_once('config.inc.php');

if($_REQUEST["op"])
{
	$yh_data=$_REQUEST["data"];
	
	//$wenjianname=$_REQUEST["wenjianname"];
	$wenjiansize=$_REQUEST["wenjiansize"];
	$filepath=dirname(__FILE__)."/upload/session_".GetIP().".log";
	$session = fopen($filepath, 'r');
	if($session)
	{
		while (!feof($session)) {
    		$wenjiannames[] = fgets($session, 4096);
   
			}
	}
	if(is_array($wenjiannames)&&count($wenjiannames)>0)
	{
		
		foreach ($wenjiannames as $v)
		{
			if(strlen(trim($v))>0)
			{
				if(strstr($v,"|"))
				{
					$p1=explode('|',$v);
					foreach ($p1 as $f)
					{
						$wenjianname[]=preg_replace("[\r\n]", "", trim($f)) ;
					}
				}
				else 
				{
					$wenjianname[]=preg_replace("[\r\n]", "", trim($v)) ;
				}
			}
		}
		
		
		if(is_file($filepath))
		{
			$filepath=dirname(__FILE__)."/upload/session_".GetIP().".log";
			$session = fopen($filepath, 'w');
			fputs($session,  '');
			fclose($session);
			//unlink($filepath);
		}
	}
	
	/*$wenjiannames=$_SESSION["uploadfiles"];
	$wenjianname=array();
	if(is_array($wenjiannames)&&count($wenjiannames)>0)
	{
		foreach ($wenjiannames as $files)
		{
			$wenjianname[]=$files;
		}
	}
	$_SESSION["uploadfiles"]='';
	unset($_SESSION["uploadfiles"]);
	*/
	//以下注释了吧 先不使用这个功能  以后要使用数据库
	/*$data=date("Ymd",time());
	$toFileFloder = dirname(__FILE__).'/upload/'.$data;
	if(!is_dir($toFileFloder))
	{
		@mkdir($toFileFloder);
	}
	@chmod($toFileFloder,0777);
	$addr = gethostbyaddr($_SERVER['REMOTE_ADDR']);
	
	$log = fopen($toFileFloder.'/UploadFile-'.$data.".log", 'a');
	*/
	$toFileFloder = dirname(__FILE__).'/upload/';
	if(!is_dir($toFileFloder))
	{
		@mkdir($toFileFloder);
		@chmod($toFileFloder,0777);
	}
	
	//$addr = gethostbyaddr($_SERVER['REMOTE_ADDR']);
	
	$log = fopen($toFileFloder.'/UploadFile.log', 'a');
	$str_fild="";
	$str_name="";
	if(is_array($yh_data)&&count($yh_data)>0)
	{
		foreach ($yh_data as $v)
		{
			if($str_fild=="")
			{
				$str_fild=$v;
			}
			else 
			{
				$str_fild=$str_fild."|||".$v;
			}
		}
	}
	if(is_array($wenjianname)&&count($wenjianname)>0)
	{
		foreach ($wenjianname as $k=>$v)
		{
			if($str_name=="")
			{
				$str_name=str_replace("\\","",$v)."|&|".$wenjiansize[$k] ;
				//$str_name=$v."|&|".$wenjiansize[$k] ;
			}
			else 
			{
				$str_name=$str_name."|*|".str_replace("\\","",$v)."|&|".$wenjiansize[$k] ;
				//$str_name=$str_name."|*|".$v."|&|".$wenjiansize[$k] ;
			}
		}
	}
	$str=$str_name."|||".date("y-m-d H:i",time())."|||".$str_fild;
	fputs($log, $str."\n");
	fclose($log);

	$referer = $_SERVER["HTTP_REFERER"];
	if( !$referer ){
		$referer = 'file.php';
	}

	echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
	echo "<script>";
	echo "alert('".$lang["上传成功说明"]."');";
	echo "window.location.href='".$referer."'";
	echo "</script>";
}
?>